package ui.commodityman;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JFrame;

import tool.MyButton;
import tool.MyLabel;
import ui.commodity.CommodityManagementPanel;
import ui.commodity.CommodityTypeManagementPanel;
import ui.commodity.StockManagerWelcomePanel;
import ui.commodity.StockOverflowDocumentPanel;
import ui.commodity.StockScrapDocumentPanel;
import ui.commodity.StockSearchPanel;
import ui.commodity.StockCheckPanel;
import ui.commodity.StockSendDocumentPanel;
import ui.commodity.StockWarningDocumentPanel;
import vo.UserVo;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JPanel;

public class CommodityManagerFrame extends JFrame {
	private static final long serialVersionUID = 1L;
	UserVo user;
	JPanel panel;

	public CommodityManagerFrame(UserVo user) {
		this.setContentPane(new JPanel() {

			private static final long serialVersionUID = -8067534092982934270L;

			@Override
			public void paint(Graphics g) {
				this.setBackground(new Color(0, 0, 0, 0));
				Image background = Toolkit.getDefaultToolkit().getImage(
						"Graphics/framebackground.jpg");
				g.drawImage(background, 0, 0, null);
				super.paint(g);
			}
		});

		this.user = user;
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.addWindowListener(new WindowListener() {
			
			@Override
			public void windowOpened(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowIconified(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowDeiconified(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowDeactivated(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowClosing(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void windowClosed(WindowEvent e) {
				System.exit(0);
			}
			
			@Override
			public void windowActivated(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
		});
		this.setSize(900, 536);
		this.setResizable(false);
		 this.setLayout(null);
		this.setVisible(true);

		JButton btnWelcomePanel = new MyButton("Graphics/Button113-23.png");
		btnWelcomePanel.setText("主界面");
		btnWelcomePanel.addActionListener(e -> StockManagerWelcomeManagement(user));
		btnWelcomePanel.setBounds(10, 41, 113, 23);
		this.add(btnWelcomePanel);

		StockManagerWelcomeManagement(user);
		JLabel label = new MyLabel("商品信息管理");
		label.setBounds(31, 96, 78, 15);
		this.add(label);

		JButton btnCommodityTypeManagement =new MyButton("Graphics/Button113-23.png");
		btnCommodityTypeManagement.setText("商品分类管理");
		btnCommodityTypeManagement.addActionListener(e -> CommodityTypeManagement(user));
		btnCommodityTypeManagement.setBounds(10, 152, 113, 23);
		this.add(btnCommodityTypeManagement);

		JButton btnCommodityManagement = new MyButton("Graphics/Button113-23.png");
		btnCommodityManagement.setText("商品管理");
		btnCommodityManagement.addActionListener(e -> CommodityManagement(user));
		btnCommodityManagement.setBounds(10, 119, 113, 23);
		this.add(btnCommodityManagement);

		JLabel lblStockManagement = new MyLabel("库存管理");
		lblStockManagement.setBounds(42, 211, 54, 15);
		this.add(lblStockManagement);

		JButton button_2 = new MyButton("Graphics/Button113-23.png");
		button_2.setText("库存查看");
		button_2.addActionListener(e -> StockSearchManagement(user));
		button_2.setBounds(10, 232, 113, 23);
		this.add(button_2);

		JButton button_3 = new MyButton("Graphics/Button113-23.png");
		button_3.setText("库存盘点");
		button_3.addActionListener(e -> StockCheckManagement(user));
		button_3.setBounds(10, 265, 113, 23);
		this.add(button_3);

		JLabel lblCreateDocuments = new MyLabel("单据制定");
		lblCreateDocuments.setBounds(42, 318, 54, 15);
		this.add(lblCreateDocuments);

		JButton btnStockSend = new MyButton("Graphics/Button113-23.png");
		btnStockSend.setText("库存赠送单");
		btnStockSend.addActionListener(e -> createStockSendDocuments(user));
		btnStockSend.setBounds(10, 342, 113, 23);
		this.add(btnStockSend);

		JButton btnStockOverflow =new MyButton("Graphics/Button113-23.png");
		btnStockOverflow.setText("库存报溢单");
		btnStockOverflow
				.addActionListener(e -> createStockOverflowDocuments(user));
		btnStockOverflow.setBounds(10, 375, 113, 23);
		this.add(btnStockOverflow);

		JButton btnStockScrap = new MyButton("Graphics/Button113-23.png");
		btnStockScrap.setText("库存报损单");
		btnStockScrap.addActionListener(e -> createStockScrapDocuments(user));
		btnStockScrap.setBounds(10, 408, 113, 23);
		this.add(btnStockScrap);

		JButton btnStockWarning = new MyButton("Graphics/Button113-23.png");
		btnStockWarning.setText("库存报警单");
		btnStockWarning
				.addActionListener(e -> createStockWarningDocuments(user));
		btnStockWarning.setBounds(10, 441, 113, 23);
		this.add(btnStockWarning);

	}

	public void CommodityManagement(UserVo user) {
		if(panel!=null){
			panel.setVisible(false);
			remove(panel);
		}
		panel = new CommodityManagementPanel(user);
		panel.setBounds(160,40,746,433);
		this.add(panel);
	}

	public void CommodityTypeManagement(UserVo user) {
		if(panel!=null){
			panel.setVisible(false);
			remove(panel);
		}
		panel = new CommodityTypeManagementPanel(user);
		panel.setBounds(160,40,746,433);
		this.add(panel);
	}

	public void StockSearchManagement(UserVo user) {
		if(panel!=null){
			panel.setVisible(false);
			remove(panel);
		}
		panel = new StockSearchPanel(user);
		panel.setBounds(160,40,746,433);
		this.add(panel);
	}

	public void StockCheckManagement(UserVo user) {
		if(panel!=null){
			panel.setVisible(false);
			remove(panel);
		}
		panel = new StockCheckPanel(user);
		panel.setBounds(160,40,746,433);
		this.add(panel);
	}

	public void StockManagerWelcomeManagement(UserVo user) {
		if(panel!=null){
			panel.setVisible(false);
			remove(panel);
		}
		panel = new StockManagerWelcomePanel();
		panel.setBounds(160,40,746,433);
		this.add(panel);
	}

	public void createStockSendDocuments(UserVo user) {// 库存赠送单
		if(panel!=null){
			panel.setVisible(false);
			remove(panel);
		}
		panel = new StockSendDocumentPanel(user, null, true,false,false);
		panel.setBounds(160,40,746,433);
		this.add(panel);
	}

	public void createStockOverflowDocuments(UserVo user) {// 库存报溢单
		if(panel!=null){
			panel.setVisible(false);
			remove(panel);
		}
		panel = new StockOverflowDocumentPanel(user, null,true,false,false);
		panel.setBounds(160,40,746,433);
		this.add(panel);
	}

	public void createStockScrapDocuments(UserVo user) {// 库存报损单
		if(panel!=null){
			panel.setVisible(false);
			remove(panel);
		}
		panel = new StockScrapDocumentPanel(user, null, true,false,false);
		panel.setBounds(160,40,746,433);
		this.add(panel);
	}

	public void createStockWarningDocuments(UserVo user) {// 库存报警单
		if(panel!=null){
			panel.setVisible(false);
			remove(panel);
		}
		panel = new StockWarningDocumentPanel();
		panel.setBounds(160,40,746,433);
		this.add(panel);
	}

}
